<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"%>
<%@ page import="beans.Manager" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
<title>管理员</title>
<link type="text/css" rel=stylesheet href="${pageContext.request.contextPath}\css\managerInfo.css">
</head>
<%
Manager manager=(Manager)session.getAttribute("manager");				//获得从Login创建成功的用户对象
String path=request.getContextPath();
String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";		//得到整个文件上下文的基本路径//防止用户因为路径问题照片显示不出来
//System.out.println(basePath);
%>
<script type="text/javascript">
function close2(){
	window.opener=null;
	window.open(location,'_self').close();	
	window.open("../window.jsp");	
	
}</script>
<body onload="showInfo('用户借书')">
<div id="main">
<div id="header">
<div id="wel">欢迎登录蚌埠学院图书馆</div>
<div id="type">管理员界面</div>
<div id="username">你好:<%=manager.getName() %></div>
<div id="quit"><a href="javascript:close2()">退出登录</a></div>
</div>
<div id="select">
<br>
<div id="用户借书" onClick="showInfo(id)"><span>用户借书</span></div>
<br>
<div id="用户还书" onClick="showInfo(id)"><span>用户还书</span></div>
<br>
<div id="图书查询" onClick="query(id)"><span>图书查询</span></div>
<br>
<div id="超期书籍" onClick="showInfo(id)"><span>超期书籍</span></div>
<br>
<div id="借阅卡注册" onClick="showInfo(id)"><span>借阅卡注册</span></div>
<br>
<div id="添/删书籍" onClick="showInfo(id)"><span>添/删书籍</span></div>
<br>
</div>
<div id="content">
</div>

</div>
</body>
<script>

function query(){
	console.log("query");
	window.open("../bookInfo.jsp");
}

function showInfo(e){
	var url;
	var xmlHttp=new XMLHttpRequest();
	if(e=='用户借书'){
		url="../borrow_book.jsp";
		console.log("test");
	}else if(e=='用户还书'){
		url='../return_book.jsp'
	}
	else if(e=='借阅卡注册'){
		url="../registerUser.jsp";
	}else if(e=='添/删书籍'){
		url="../addBook.jsp";
	}else if(e=='超期书籍'){
		url="OverTimeBook";
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			document.getElementById("content").innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.send();
}





function clear(){
	document.getElementById('alert').innerHTML='';
	console.log('alert');
}

function borrow(){			//借书
	
	var card_num=document.getElementById('card_num').value;
	var ID=document.getElementById('ID').value;
	var url="BorrowBook?card_num="+card_num+"&ID="+ID;
	console.log(url);
	var xmlHttp=new XMLHttpRequest();
	
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function(){
		
		if(xmlHttp.readyState==4){
			document.getElementById('alert').innerHTML=xmlHttp.responseText;
		}
		
	}
	xmlHttp.send();
}
function return_book(){				//还书
	var ID=document.getElementById('id').value;
	console.log(ID);
	var url="ReturnBook?ID="+ID;
	var xmlHttp=new XMLHttpRequest();
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			document.getElementById('tip').innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.send();
}

function check(){			//检查借阅卡号是否存在
	var id=document.getElementById('id').value;
	var url="Register?id="+id+"&identity=1234";
	var xmlHttp=new XMLHttpRequest();	
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			document.getElementById('tip').innerHTML=xmlHttp.responseText;
			console.log(xmlHttp.responseText);
			var str=xmlHttp.responseText;
			if(str.trim()=='已存在'.trim()){
				document.getElementById('sub').setAttribute("disabled",true);
			}else if(str.trim()=='正常'.trim())
				{
				document.getElementById('sub').removeAttribute("disabled");

				}
		}
		
	}
	xmlHttp.send();
}




function register(){			//注册用户
	var name=document.getElementById('name').value;
	var id_card=document.getElementById('id_card').value;
	var id=document.getElementById('id').value;
	var password=document.getElementById('password').value;
	var xmlHttp=new XMLHttpRequest();
	var url="Register?name="+name+"&id_card="+id_card+"&id="+id+"&password="+password;
	xmlHttp.open("GET",url,true);
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==4){
			document.getElementById('message').innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.send();
}


function send(){				//发布公告
	var message=document.getElementById('message');
	var info=document.getElementById('area').value;
	message.innerHTML+="<span>"+info+"<button>删除</button></span>"+"<br>";
}
</script>



</html>